//
//  dSliderViewController.m
//  Surveyer
//
//  Created by Qikun Guo on 13-7-30.
//  Copyright (c) 2013年 Tim. All rights reserved.
//

#import "dSliderViewController.h"

@interface dSliderViewController ()
@property (weak, nonatomic) IBOutlet UILabel *minLabel;
@property (weak, nonatomic) IBOutlet UILabel *maxLabel;

@end

@implementation dSliderViewController
@synthesize slider, sliderLabel, titleLabel, currentItem, currentResult;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    titleLabel.text = self.currentItem.title;
    
    slider.minimumValue = currentItem.value1.floatValue;
    slider.maximumValue = currentItem.value2.floatValue;
    
    sliderLabel.text = currentResult.text;
    slider.value = [currentResult.text floatValue];
    self.minLabel.text = currentItem.value1;
    self.maxLabel.text = currentItem.value2;
    
    [slider setValue:(slider.minimumValue+slider.maximumValue)/2 animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sliderAction:(id)sender {
    self.editCount ++;
    [self.delegate currentItemCompleted:self];
}
- (IBAction)valueChanged:(id)sender {
    //if ([currentItem.value3 boolValue])
    if (!currentResult)
        currentResult = [[SurveyerStore defaultStore] createResultWithSurveyItem:currentItem];
    currentResult.text = [NSString stringWithFormat:@"%d",(int)(slider.value + 0.5)];
    sliderLabel.text = currentResult.text;
    //else
    //sliderLabel.text = currentResult.text = [NSString stringWithFormat:@"%f", slider.value];
}

@end
